#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 3e5+10;

int a[N],n;

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 0;i < n;i++) a[i] = in;
	int i = 0,j = 1,k = 0;
	while(i < n && j < n && k < n){
		if(a[(i+k)%n] > a[(j+k)%n]) i = i + k + 1,k = 0;
		else if(a[(i+k)%n] < a[(j+k)%n]) j = j + k + 1,k = 0;
		else k++;
		if(i == j) i++;
	}
	int ans = min(i,j);
	for(int i = 0;i < n;i++) printf("%d%c",a[(i+ans)%n]," \n"[i==n-1]);
	return 0;
}

